class Draw{
    constructor(canvas){
        this.ctx = canvas.getContext("2d");
    }
    // 配置项解析
    config(config){
        let ctx = this.ctx;
        let {background,color,lineWidth} = config
        if(lineWidth){ ctx.lineWidth = lineWidth }
        if(color){ ctx.strokeStyle = color }
        if(background){ ctx.fillStyle=background }
    }
    // 坐标参数解析
    arguments(place){
        let arr = place.split(",")
        let site = arr.reduce((current,item,index)=>{
            if(index%2 === 0){
                current = [...current,[item]]
            }else{
                let length = current.length
                current[length-1].push(item)
            }
            return current
        },[])
        return site
    }

    // 点
    Point(place,config={}){
        let ctx = this.ctx;
        let site = this.arguments(place)
        let {radius,start,end} = config
        //设置绘制颜色
        //绘制成矩形
        // ctx.arc(point.x, point.y,5, 0, Math.PI * 5);
        for(let i = 1;i<site.length ;i++){
            ctx.beginPath();
            this.config(config)
            ctx.arc(...site[i], radius||100, start || 0, end || 2 * Math.PI)
            ctx.stroke() 
            ctx.fill()
            ctx.closePath();
        }
    }
    // 线
    Path(place,config){
        let ctx = this.ctx;
        let site = this.arguments(place)
        ctx.beginPath();
        this.config(config)
        ctx.moveTo(...site[0]);
        for(let i = 1;i<site.length ;i++){
            ctx.lineTo(...site[i]);
        }
        ctx.stroke();
        ctx.closePath();
    }
    // 面
    Area(place,config){
        let ctx = this.ctx;
        this.Path(place,config)
        ctx.fill()
    }
    // 圆形
    // 矩形
}
export default Draw